#ifndef _THREADPOOL_H
#define _THREADPOOL_H
#include "TaskQueue.hpp"
#include "Thread.hpp"
#include "Nocopyable.hpp"
#include <vector>
#include <memory>
using std::vector;
using std::unique_ptr;

class ThreadPool:public Nocopyable
{
public:
    ThreadPool(int,int);
    ~ThreadPool(){};

    void start();
    void stop();
    void addTask(task*);
    void doTask();
    static bool isExit;
private:
    class workThread:public Thread
    {
    public:
        workThread(ThreadPool & pool):_pool(pool){}
    private:
        void run()override{
            _pool.doTask();
        }
    private:
        ThreadPool & _pool;
    };
private:
    vector<unique_ptr<Thread>> threadpool;
    int capacity;
    TaskQueue task_queue;
};
#endif

